<template>
  <div class="container">
    <el-row>
      <el-form ref="form" :model="form" label-width="150px">
        <el-form-item
          label="组合介绍："
          prop="content"
          :rules="[{ required: true, message: '组合介绍不能为空' }]"
        >
          <tinymce
            v-model="form.content"
            :height="400"
            @input="handleContent"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit('form')" :loading="loading"
            >保存</el-button
          >
        </el-form-item>
      </el-form>
    </el-row>
  </div>
</template>

<script>
import normalFilter from "@/components/NormalFilter";
import Upload from "@/components/UploadFile";
import Tinymce from "@/components/Tinymce";
import { Message } from "element-ui";
import { getDescDetail, saveDesc } from "@/api/productComb";
import { getList } from "@/api/productComb";

export default {
  name: "bannerAdd",
  components: {
    normalFilter,
    Tinymce,
    Upload
  },
  data() {
    return {
      loading: false,
      id: "",
      form: {
        content: ""
      }
    };
  },
  async mounted() {
    let { id } = this.$route.params;
    this.id = id;

    let info = await getDescDetail({ productId: id });
    if (info) {
      this.form = info;
    }
  },
  methods: {
    onSubmit(formName) {
      const { validate } = this.$refs[formName];
      validate(valid => {
        if (valid) {
          this._submitData(this.form);
        }
      });
    },
    async _submitData(params) {
      this.loading = true;
      let res = await saveDesc({ ...params, productId: this.id });
      this.loading = false;
      if (res.code === 1) {
        Message({
          message: "保存成功！",
          type: "success",
          duration: 1 * 1000
        });
        setTimeout(() => {
          this.$router.go(-1);
        }, 1000);
      }
    },
    handleContent(val) {
      this["form"]["content"] = val;
    }
  }
};
</script>

<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  padding: 20px;
  .radio-form {
    ::v-deep .el-form-item__error {
      left: 5%;
    }
  }
  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
}
</style>
